package com.loong.user.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.user.common.forehead.param.login.LoginParam;
import com.loong.user.model.UserVerification;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Component
public class UserVerificationBusiness extends AbstractBusiness<UserVerification> {

    /**
     * @param loginParam
     */
    public UserVerification verify(LoginParam loginParam){
        Condition condition = new Condition(UserVerification.class);
        Condition and = new Condition(UserVerification.class);
        Example.Criteria criteria = condition.createCriteria();

        if(ObjectUtils.isNotEmpty(loginParam.getAreaCode())){
            // 手机号登陆
            criteria.andEqualTo("mobile",loginParam.getUniqueAccount())
                    .andEqualTo("telArea",loginParam.getAreaCode());
        }else {
            // 邮箱和用户账号登陆
            criteria.orEqualTo("username", loginParam.getUniqueAccount())
                    .orEqualTo("email", loginParam.getUniqueAccount());
        }
        Example.Criteria password = and.createCriteria().andEqualTo("password", loginParam.getPassword());
        condition.and(password);
        List<UserVerification> byCondition = findByCondition(condition);
        if(ObjectUtils.isEmpty(byCondition)){
            return null;
        }else {
            return byCondition.get(0);
        }
    }
    /**
     * 三方授权登陆
     */



}
